<?php
class ConfigBase extends BaseDBModel
{
    public function __construct()
    {
        $this->tableName = 'config';
        $this->primaryKey = 'name';
    }

    public function getSettings()
    {
        $arr = array();
        $tbl = $this->get('1=1');
        foreach ($tbl as $row) {
            $arr[$row['name']] = $row['value'];
        }
        return $arr;
    }

    public function setSettings($settings)
    {
        Yii::app()->cache->delete('registry_' . $this->tableName);
        $transaction = Yii::app()->db->beginTransaction();
        try {
            while (current($settings) !== false) {
                $val = current($settings);
                $this->update(array('value' => $val), 'name=:name', array(':name' => key($settings)));
                next($settings);
            }
            $transaction->commit();
        } catch (Exception $e) {
            $transaction->rollback();
            Yii::log($e->getMessage(), 'error');
        }
    }
}